import sys
import os.path
import os

VERBPATH=os.path.expanduser(os.path.join("~", ".glassbead", "verbs"))
PROCESSORPATH=os.path.expanduser(os.path.join("~", ".glassbead", "processors"))

class VerbManager:
    def __init__(self):
        self.loadverbs()

    def loadverbs(self):
        if os.path.exists(PROCESSORPATH):
            sys.path.append(PROCESSORPATH)
        else:
            print "Creating processor directory"
            os.makedirs(PROCESSORPATH)
            print PROCESSORPATH


        if os.path.exists(VERBPATH):
            sys.path.append(VERBPATH)
            self.VERBS={}
            verbmodules=[module[0:-3]  for module in os.listdir(VERBPATH) if module.endswith('.py')]
            for verbmodule in verbmodules:
                try:
                    module=__import__(verbmodule)
                    VerbClass=module.VERBCLASS
                    VerbObj=getattr(module,VerbClass)
                    self.VERBS[verbmodule]=VerbObj()
                except Exception,ex:
                    print ex
                    print "Error loading verb "+verbmodule
                    print "Please make sure that the verb class is correct and required processors are present in processor directory"
        else:
            print "Creating verbs directory"
            os.makedirs(VERBPATH)
            print VERBPATH



if __name__=="__main__":
    a=VerbManager()
    print a.VERBS